var UCommerceClientMgr = {

    openModal: function (url, name, width, height) {
        UmbClientMgr.openModalWindow(url, name, true, width, height);
    },

    getCurrentNodeId: function () {
        return UmbClientMgr.mainTree().getActionNode().nodeId;
    },

    contentFrame: function (url) {
        window.setTimeout(function () {
            if (typeof UmbClientMgr.mainWindow().right != "undefined") {
                UmbClientMgr.mainWindow().right.location.href = url;
            }
            else {
                UmbClientMgr.mainWindow().location.href = url; //set the current windows location if the right frame doesn't exist int he current context
            }
        }, 200);

        // Not using the standard function from Umbraco
        // as it messes around with the URL if 
        // setUmbracoPath is not called on each page.
        // All uCommerce URLs include full path so
        // no handling of URLs with missing CMS
        // path is required.
        //UmbClientMgr.contentFrame(url);
    },

    refreshTree: function (nodeId) {
        // Set current node context (only way to get the right context to reloadActionNode()
        UmbClientMgr.mainTree().onBeforeContext(UmbClientMgr.mainTree().findNode(nodeId, true))
        UmbClientMgr.mainTree().reloadActionNode(false, false, null);
    },
    refreshTree: function () {
        // Set current node context (only way to get the right context to reloadActionNode()
        UmbClientMgr.mainTree().onBeforeContext(UmbClientMgr.mainTree().findNode(UmbClientMgr.mainWindow().jQuery('.sprTree.noSpr.clicked').parent().attr('id'), true))
        UmbClientMgr.mainTree().reloadActionNode(false, false, null);
    },

    updateCurrentNodeText: function (nodeText) {
        UmbClientMgr.mainWindow().jQuery(".sprTree.noSpr.clicked > div").text(nodeText);
    },

    childNodeCreated: function () {
        UmbClientMgr.mainTree().childNodeCreated();
    },

    // For instance nodeId can be Category_67
    findAndSelectNode: function (nodeId) {
        var node = UmbClientMgr.mainTree().findNode(nodeId, true);
        if (node != null)
            UmbClientMgr.mainTree().selectNode(node, true, true);
    },

    closeModalWindow: function (url) {
        UmbClientMgr.closeModalWindow(url);
    },

    showSpeechBubble: function (icon, header, body) {
        UmbClientMgr.mainWindow().UmbSpeechBubble.ShowMessage(icon, header, body);
    },

    setFocusToTreeNode: function (treeNode) {
        UmbClientMgr.mainTree().selectNode(node, false, true);
    },

    showPopupWindow: function (url, width, height, saveFunction) {
        UmbClientMgr.openModalWindow(this._itemPickerUrl, this._label, this._showHeader, this._width, this._height, 60, 0, ['#cancelbutton'], function (e) { _this.SaveSelection(e); });
    }
}

function sortCategoryThis() {
    UCommerceClientMgr.openModal('ucommerce/catalog/dialogs/SortCatalog.aspx?id=' + UCommerceClientMgr.getCurrentNodeId(), 'Sort', 600, 450);
};

function sortProductsThis() {
    UCommerceClientMgr.openModal('ucommerce/catalog/dialogs/SortCatalog.aspx?id=' + UCommerceClientMgr.getCurrentNodeId() + '&products=1', 'Sort', 600, 450);
};



